//
//  XJTieZiDetailHeaderView.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/6/7.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJTieZiDetailHeaderView.h"
@interface XJTieZiDetailHeaderView()
@property(nonatomic, strong) UIImageView *iconIv; // 1.头像
@property(nonatomic, strong) UILabel *nameLb; // 2.姓名:张三
@property(nonatomic, strong) UILabel *timeLabel; // 3.时间
@property(nonatomic, strong) UILabel *tieZiContentLb; // 4.帖子内容Lb
@property(nonatomic, strong) UILabel *howHourTimeAgoLb; // 5.多少小时前
@property(nonatomic, strong) UILabel *browseTimesLb; // 6.浏览次数


@end

@implementation XJTieZiDetailHeaderView
#pragma mark - 一 初始化


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    return self;
}

- (void)setupView{
    [self addSubview:self.iconIv];
    [self addSubview:self.nameLb];
    [self addSubview:self.timeLabel];
    [self addSubview:self.tieZiContentLb];
    [self addSubview:self.howHourTimeAgoLb];
    [self addSubview:self.browseTimesLb];
}

#pragma mark - 二 lazy
- (UIImageView *)iconIv {
    if (!_iconIv) {
        _iconIv = [[UIImageView alloc] init];
        // 切圆角 25
        
        _iconIv.layer.masksToBounds = YES;
        _iconIv.layer.cornerRadius = 25;
    }
    return _iconIv;
}

- (UILabel *)nameLb {
    if (!_nameLb) {
        _nameLb = [UILabel new];
    }
    return _nameLb;
}
- (UILabel *)timeLabel {
    if (!_timeLabel) {
        _timeLabel = [UILabel new];
    }
    return _timeLabel;
}
- (UILabel *)tieZiContentLb {
    if (!_tieZiContentLb) {
        _tieZiContentLb = [UILabel new];
        _tieZiContentLb.numberOfLines = 0; //高度自适应
    }
    return _tieZiContentLb;
}
- (UILabel *)howHourTimeAgoLb {
    if (!_howHourTimeAgoLb) {
        _howHourTimeAgoLb = [UILabel new];
        _howHourTimeAgoLb.font = XJFONTSET_R(13.0);
    }
    return _howHourTimeAgoLb;
}

- (UILabel *)browseTimesLb {
    if (!_browseTimesLb) {
        _browseTimesLb = [UILabel new];
        _browseTimesLb.font = XJFONTSET_R(13.0);
        _browseTimesLb.textColor = [UIColor lightGrayColor];
        _browseTimesLb.textAlignment = NSTextAlignmentRight;
    }
    return _browseTimesLb;
}


#pragma mark - 三 layout
- (void)layoutSubviews {
    [super layoutSubviews];
    
    CGFloat kLeftMargin = 15;
    CGFloat k5 = 5;
    // w:50 h:50
    [self.iconIv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(kLeftMargin);
        make.top.equalTo(self.mas_top).offset(k5);
        make.size.mas_equalTo(CGSizeMake(50, 50));
    }];
    
    [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconIv.mas_right).offset(k5);
        make.top.equalTo(self.iconIv.mas_top);
        make.size.mas_equalTo(CGSizeMake(100, 25));
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconIv.mas_right).offset(k5);
        make.bottom.equalTo(self.iconIv.mas_bottom);
        make.size.mas_equalTo(CGSizeMake(200, 20));
    }];
    
    
    // 不给高高度自适应
    [self.tieZiContentLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(kLeftMargin);
        make.top.equalTo(self.iconIv.mas_bottom).offset(k5);
        make.right.equalTo(self.mas_right).offset(-kLeftMargin);
        make.bottom.equalTo(self.howHourTimeAgoLb.mas_bottom).offset(-k5);
    }];
    
    [self.howHourTimeAgoLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(kLeftMargin);
        make.bottom.equalTo(self.mas_bottom).offset(-k5);
        make.size.mas_equalTo(CGSizeMake(100, 20));
    }];
    
    [self.browseTimesLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-k5);
        make.bottom.equalTo(self.mas_bottom).offset(-k5);
        make.size.mas_equalTo(CGSizeMake(100, 20));
    }];
}

#pragma mark - 四 配置

- (void)configureIcon:(NSString *)iconStr name:(NSString *)name time:(NSString *)time content:(NSString *)contentStr howHourAge:(NSString *)ago browseTimes:(NSString *)count {
    UIImage *placehodler = [UIImage imageNamed:@"placeholderImg"];
    NSURL *imgURL = [NSURL URLWithString:iconStr];
    
    [self.iconIv sd_setImageWithURL:imgURL placeholderImage:placehodler];
    self.nameLb.text = name;
    self.timeLabel.text = time;
    self.tieZiContentLb.text = contentStr;
    self.howHourTimeAgoLb.text = ago;
    self.browseTimesLb.text = [NSString stringWithFormat:@"%@浏览",count];
}




@end
